var PROXY, SUPPORT_WEBP, Script, get_mail, mail, origin, pathname, u, url;

({pathname} = location);

pathname = pathname.slice(1);

if ($('a[data-portal=signup]')[0]) {
  if (pathname) {
    localStorage.url = pathname;
  }
} else {
  if (!pathname.startsWith('members/')) {
    ({url} = localStorage);
    if (url) {
      if (!pathname) {
        location.href = '/' + url;
      }
      delete localStorage.url;
    }
  }
}

SUPPORT_WEBP = !![].map && document.createElement('canvas').toDataURL('image/webp').indexOf('data:image/webp') === 0;

PROXY = location.protocol + "//blog-img.xvc.com/0/";

origin = location.origin + "/";

$('.gh-content img').each(function() {
  var src;
  src = this.src;
  if (!src || src.indexOf("://") < 0) {
    return;
  }
  if (!SUPPORT_WEBP) {
    // 微信公众号图片
    src = src.replace("=webp", "=jpg").replace("%3Dwebp", "%3Djpg");
  }
  if (!src.split("/")[2].endsWith(".xvc.com")) {
    src = PROXY + encodeURIComponent(src);
  }
  if (src !== this.src) {
    return this.src = src;
  }
});

if (navigator.userAgent.indexOf('MicroMessenger') + 1) {
  $.getScript("//blog-js.xvc.com/wx.js?a");
}

mail = void 0;

window._hmt = window._hmt || [];

get_mail = async() => {
  if (mail) {
    return mail;
  }
  mail = (await ((await fetch('/members/api/member'))).text());
  if (mail) {
    mail = JSON.parse(mail).email;
    _hmt.push(['_setUserId', mail]);
  }
  return mail;
};

window.addEventListener('message', async(e) => {
  if (e.data === 'mail') {
    await get_mail();
    if (mail) {
      e.source.postMessage(mail, '*');
    }
  }
});

window.addEventListener('load', async() => {
  var href, iframe, ir_a, ref;
  ref = document.getElementsByTagName('iframe');
  for (iframe of ref) {
    if (iframe.src.startsWith('https://blog-play.xvc.com/')) {
      await get_mail();
      iframe.contentWindow.postMessage(mail, '*');
    }
  }
  ir_a = $('a.ir')[0];
  if (ir_a) {
    ({href} = ir_a);
    ir_a.href = href.slice(0, 7) + encodeURI(decodeURI(ir_a.href.slice(7)).replace('/ ', location.pathname + ' '));
  }
});

Script = function(src) {
  var hm, s;
  hm = document.createElement('script');
  hm.src = '//' + src;
  s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(hm, s);
};

window._paq = window._paq = window._paq || [];

_paq.push(['trackPageView']);

_paq.push(['enableLinkTracking']);

_paq.push(['setSiteId', '2']);

u = "//tj.xvc.com/";

_paq.push(['setTrackerUrl', u + 'matomo.php']);

Script(u + 'tj');
